package com.project.authorize;

import com.project.redis.RedisCache;
import com.project.redis.RedisKey;
import com.project.utils.DbMessageHolder;
import com.project.utils.JwtUtil;
import com.project.vo.DbMessageVO;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.awt.print.Book;
import java.util.Set;


/**
 * @Author: jia-qiang ljq1024.cc
 * @desc: 数据库权限认证
 * @Date: 2024-04-29-20:10
 */
@Slf4j
@Component("ex")
public class DbAuthService {

    /**
     *  作者删除 / 修改 / 获取书籍信息的权限
     */
    public boolean hasAnyDbDatabases(String token) {
        try {
            // 拿到作者id, 判断是否合法
            DbMessageVO dbMessageVO = JwtUtil.parseDbMessageVO(token);
            if (dbMessageVO == null) {
                return false;
            }
            // 将信息放入 ThreadLocal 中
            DbMessageHolder.saveDbMessageVO(dbMessageVO);
            return true;
        } catch (Exception e) {
            log.error("未知错误：", e);
            return false;
        }
    }
}
